package com.easy.admin.system.test.netty;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 *
 * @author wangbo
 * @deprecated netty client
 */
public class NettyClient {
    public static void main(String[] args) throws Exception{
        //创建线程池
        EventLoopGroup group = new NioEventLoopGroup();
        //创建启动类
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(group)
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel socketChannel) throws Exception {
                        socketChannel.pipeline().addLast(new NettyClientHandler());
                    }
                });

        try {
            //连接服务
            Channel channel = bootstrap.connect("127.0.0.1", 9090).sync().channel();
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.exit(1);
        } finally {
            group.shutdownGracefully();
        }
    }

}
